/*
* general purpose data container
*/
#pragma once
#include <vector>
#include "utils.h"

namespace vkinfer
{
    template<typename T>
    struct Tensor
    {
        std::vector<uint32_t> shape;
        T* data = nullptr;

    public:
        Tensor();
        Tensor(const std::vector<uint32_t>& shape);
        // void fill(const T& value) {}

    private:
        void create(const std::vector<uint32_t>& shape);
        void destroy();
    };

    // --------------------------------------------------
    // implementations

    template<typename T>
    Tensor<T>::Tensor() {}

    template<typename T>
    Tensor<T>::Tensor(const std::vector<uint32_t>& shape)
    {
        create(shape);
    }

    template<typename T>
    void Tensor<T>::destroy()
    {
        if (data != nullptr) delete data;
    }

    template<typename T>
    void Tensor<T>::create(const std::vector<uint32_t>& shape)
    {
        uint32_t new_count = shape_size(shape);
        if (new_count == shape_size(this->shape))
        {
            this->shape = shape;
            return;
        }

        if (data != nullptr) delete data;
        this->shape = shape;
        data = new T[new_count];
    }
}
